package com.example.obmb.customer.controller;

import com.example.obmb.common.base.PageParams;
import com.example.obmb.common.base.R;
import com.example.obmb.common.base.ResponseCode;
import com.example.obmb.common.entity.CustomerDO;
import com.example.obmb.common.entity.StatementInfoDO;
import com.example.obmb.common.entity.StatementPdfDO;
import com.example.obmb.common.util.StringUtil;
import com.example.obmb.common.vo.StatementInfoResponseVO;
import com.example.obmb.customer.service.ICustomerSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 用户账户信息
 */
@RestController
@RequestMapping("/eStatement")
public class CustomerController {

    @Autowired
    private ICustomerSerivce customerService;

    /**
     * 获取账户电子账单选项
     * @param cif 客户号码
     * @param productType 产品类型
     * @return 电子账单列表
     */
    @RequestMapping(value = "/getCustomerEstatementType", method = {RequestMethod.GET})
    @ResponseBody
    public R<Object> getCustomerEstatementType(@RequestParam("cif") String cif,@RequestParam("productType") String productType){
        if (StringUtil.isEmpty(cif)){
            return R.result(ResponseCode.BAD_REQUEST.getCode(),null,"客户号码为空时无法查询！");
        }
        if (StringUtil.isEmpty(productType)){
            return R.result(ResponseCode.BAD_REQUEST.getCode(),null,"无产品类型时无法查询！");
        }
        return customerService.getCustomerEstatementType(cif,productType);
    }

    /**
     * 设定投资账户是否为电子结单
     * @param customerDO   1.cif 户口号码 2.isEstatement 是否电子结单
     * @return success/not
     */
    @ResponseBody
    @PostMapping(value = "/modifyCustomerEstatementType",produces = {"application/json;charset=UTF-8"})
    public  R<Object> modifyCustomerEstatementType(@RequestBody CustomerDO customerDO){
        if (StringUtil.isEmpty(customerDO.getCif())){
            return R.result(ResponseCode.BAD_REQUEST.getCode(),null,"客户号码为空时无法查询！");
        }
        if (StringUtil.isEmpty(customerDO.getIsEstatement())){
            return R.result(ResponseCode.BAD_REQUEST.getCode(),null,"无是否电子结单类型时无法查询！");
        }
        if (!"Y".equals(customerDO.getIsEstatement()) || !"N".equals(customerDO.getIsEstatement()) ){
            return R.result(ResponseCode.BAD_REQUEST.getCode(),null,"电子账单类型不规范！");
        }
        return customerService.modifyCustomerEstatementType(customerDO);
    }

    /**
     * 查询客户名下某投资产品的结单列表
     * @param request 入参
     * @return 响应
     */
    @ResponseBody
    @PostMapping("/queryStatementInfo")
    public R<StatementInfoResponseVO> queryStatementInfo(@RequestBody PageParams<StatementInfoDO> request){
        return R.success(customerService.queryStatementInfo(request));
    }

    /**
     * 获取pdf P9USD 版
     * @param recordId 結單ID
     * @return 响应
     */
    @ResponseBody
    @GetMapping("/getPdfByP9usd")
    public  R<Object> queryStatementInfo(@RequestParam("recordId") Long recordId, HttpServletResponse response){
        return R.success(customerService.getPdfByP9usd(recordId,response));
    }

    /**
     * Documentum版
     * @param StatementPdfDO 请求
     * @return 响应
     */
    @ResponseBody
    @GetMapping("/getPdfByDocumentum")
    public R<byte[]> queryStatementInfo(StatementPdfDO StatementPdfDO){
        return R.success(customerService.getPdfByDocumentum(StatementPdfDO));
    }



}
